<template>
	<view class="page">
		<view class="wrapper">
			<view class="list">
				<uni-swipe-action>
					<uni-swipe-action-item :options="options" @click="onClick(i.id)" @change="change" v-for="i in list" :key="i.id">
						<view class="address-wrapper" @click="goto('/pages/mine/addressEdit?id=' + i.id)">
							<image class="img" src="../../static/images/pos.png" mode="aspectFill"></image>
							<view class="right main">
								<view class="row">
									<view class="name">
										{{i.name}}
									</view>
									<view class="tel">
										{{i.mobile}}
									</view>
								</view>
								<view class="address">
									{{i.province}}{{i.city}}{{i.area}}{{i.detail}}
								</view>
							</view>
							<image class="img right" src="../../static/images/next.png" mode="aspectFill"></image>
						</view>
					</uni-swipe-action-item>
				</uni-swipe-action>

				
			</view>

			<view class="padding flex flex-direction new-address">
				<button class="cu-btn bg-green lg" @click="goto('/pages/mine/addressEdit')">添加新地址</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}]
			}
		},
		onShow() {
			this.getList();
		},
		methods: {
			goto(path) {
				uni.navigateTo({
					url: path,
					animationType: 'slide-in-right',
					animationDuration: 300
				})
			},
			getList() {
				this.$u.get('/address').then(res => {
					this.list = res.data.result.address
				})
			},
			onClick(id) {
				let data = {
					id: id
				}
				this.$u.post('/address/delete', data).then(res => {
					if (res.data.success) {
						this.getList();
					}
				})
			},
			change(open) {
				console.log('当前开启状态：' + open)
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import url("/colorui/main.css");
	
	.list {
		padding-bottom: 100rpx;
	}

	.new-address {
		position: fixed;
		bottom: 0;
		width: 100%;
		left: 0;
		background: #03012A;
	}

	.bg-green {
		background: #00D28B;
	}
	
	/deep/ .uni-swipe_box {
		background-color: transparent;
	}

	.address-wrapper {
		width: 100%;
		color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 30rpx;
		margin: 30rpx 0 60rpx 0;
		
		.main {
			min-width: 500rpx;
		}

		.img {
			width: 50rpx;
			height: 50rpx;
			display: block;
			margin-right: 30rpx;
			flex: 0 0 auto;

			&.right {
				margin-left: 30rpx;
				margin-right: 0;
			}
		}

		.row {
			display: flex;
			justify-content: space-between;
			margin: 20rpx 0;
			font-size: 34rpx;
		}

		.name {
			max-width: 300rpx;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			letter-spacing: 2rpx;
		}
	}
</style>
